<template>
  <div class="container">
    <div class="app-container">
      <el-row type="flex">
        <span style="margin-top: 10px;margin-left: 15px;margin-top: 25px;">企业名称：</span>
        <el-input style="width: 200px;margin-right: 10px;margin-top: 15px;" placeholder="请输入企业名称" />
        <el-button size="mini" type="primary" style="margin-top: 15px;border-radius: 5px;">查 询</el-button>
      </el-row>
      <el-row>
        <el-button size="mini" type="primary" style="margin-left: 15px;margin-top: 15px;border-radius: 5px;">添加企业</el-button>
      </el-row>
      <el-table v-loading="loading" :data="list">
        <el-table-column label="序号" type="index" />
        <el-table-column label="企业名称" prop="name" />
        <el-table-column label="联系人" prop="contact" />
        <el-table-column label="联系电话" prop="contactNumber" />
        <el-table-column label="操作">
          <template>
            <el-button size="mini" type="text">添加合同</el-button>
            <el-button size="mini" type="text">查看</el-button>
            <el-button size="mini" type="text">编辑</el-button>
            <el-button size="mini" type="text">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-row type="flex" justify="end">
        <el-pagination
          :page-size="pageParams.pagesize"
          :current-page="pageParams.page"
          layout="prev, pager, next, total"
          :total="pageParams.total"
          @current-change="changePage"
        />
      </el-row>
    </div>
  </div>
</template>
<script>
import { getBusinessListAPI } from '@/api'

export default {
  name: 'BusinessManagement',
  data() {
    return {
      list: [],
      loading: false,
      pageParams: {
        page: 1,
        pagesize: 5,
        total: 0
      }
    }
  },
  created() {
    this.getBusinessList()
  },
  methods: {
    async getBusinessList() {
      this.loading = true
      const { rows, total } = await getBusinessListAPI(this.pageParams)
      this.list = rows
      this.pageParams.total = total
      this.loading = false
    },
    changePage(newPage) {
      this.pageParams.page = newPage // 赋值当前页码
      this.getBusinessList()
    }
  }
}
</script>
